package com.example.designpatterns.structural.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 *
 * @author scott
 */
public class ChessPieceFactory {

    private Map<String, ChessPiece> chessPieces;

    public ChessPieceFactory() {
        chessPieces = new HashMap<>();
    }

    public ChessPiece getChessPiece(String type) {
        if (!chessPieces.containsKey(type)) {
            ChessPiece chessPiece = new ConcreteChessPiece(type);
            chessPieces.put(type, chessPiece);
        }
        return chessPieces.get(type);
    }

}
